package com.tangyanbo.android.FileManager;


import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.EditText;

import static com.tangyanbo.filemanager.common.constant.DialogTextConstant.*;

public class BuilderManager {

	public static void makePasteNoCopyOrCutDialog(Context context){
		Builder builder = new Builder(context);
		builder.setTitle(PASTE_TITLE);
		builder.setMessage(Paste_NoCopyOrCut_Message);
		builder.setPositiveButton(android.R.string.ok,
				new AlertDialog.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		builder.setCancelable(false);
		builder.create();
		builder.show();
	}
	
	public static Builder makePasteExistSameFileNameDialog(Context context){		
		Builder builder = new Builder(context);
		builder.setTitle(PASTE_TITLE);
		builder.setMessage(Paste_ExistSameFileName_Message);		
		builder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog,
							int which) {
						dialog.cancel();
					}
				});
		builder.setCancelable(false);
		builder.create();		
		return builder;
	}
	
	public static Builder makeRenameFileNameIsExistDialog(Context context){
		Builder builder = new Builder(context);
		builder.setTitle(RENAME_TITLE);
		builder.setMessage(Rename_FileNameIsExist_Message);		
		builder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(
							DialogInterface dialog,
							int which) {
						dialog.cancel();
					}
				});
		builder.setCancelable(false);
		builder.create();
		return builder;
	}
	
	public static Builder makeRenameDialog(Context context,View dialogview,String fileName){
		((EditText) dialogview.findViewById(R.id.EditText01)).setText(fileName);
		Builder builder = new Builder(context);
		builder.setTitle(RENAME_TITLE);
		builder.setView(dialogview);
		builder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
			public void onCancel(DialogInterface dialog) {
				dialog.cancel();
			}
		});
		return builder;
	}
	
	public static Builder makeDeleteSuccessDialog(Context context){
		Builder builder = new Builder(context);
		builder.setTitle(DELETE_TITLE);
		builder.setMessage(Delete_Success_Message);
		builder.setCancelable(false);
		builder.create();
		return builder;
	}
	
	public static Builder makeDeleteFailureDialog(Context context){
		Builder builder = new Builder(context);
		builder.setTitle(DELETE_TITLE);
		builder.setMessage(Delete_Failure_Message);
		builder.setPositiveButton(android.R.string.ok,
				new AlertDialog.OnClickListener() {
					public void onClick(
							DialogInterface dialog,
							int which) {
						dialog.cancel();
					}
				});
		builder.setCancelable(false);
		builder.create();
		return builder;
	}
	
	public static Builder makeDeletePositiveOrCancelDialog(Context context,String fileName){
		Builder builder = new Builder(context);
		builder.setTitle(DELETE_TITLE);
		builder.setMessage(Delete_Positive_Message + fileName + Question_Mark);
		builder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		builder.setCancelable(false);
		builder.create();
		return builder;
	}
	
	public static Builder makeNewSuccessDialog(Context context){
		Builder builder = new Builder(context);
		builder.setMessage(New_Success_Message);
		builder.setCancelable(false);
		builder.create();
		return builder;
	}
	
	public static Builder makeNewFailDialog(Context context){
		Builder builder = new Builder(context);
		builder.setMessage(New_Failure_Message);
		builder.setPositiveButton(android.R.string.ok,
				new AlertDialog.OnClickListener() {
					public void onClick(
							DialogInterface dialog,
							int which) {
						dialog.cancel();
					}
				});
		builder.setCancelable(false);
		builder.create();
		return builder;
	}
	
	public static Builder makeNewFileDialog(Context context,final View dialogview){
		Builder builder = new Builder(context);
		builder.setTitle(NEW_TITLE);
		builder.setView(dialogview);
		builder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
			public void onCancel(DialogInterface dialog) {
				dialog.cancel();
			}
		});
		return builder;
	}
	
	public static Builder makeZIPDialog(Context context,View zipview,String fileName){
		((EditText) zipview.findViewById(R.id.EditText_zip))
				.setText(fileName+".zip");
		Builder builder = new Builder(context);
		builder.setTitle(ZIP_TITLE);
		builder.setView(zipview);
		builder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
			public void onCancel(DialogInterface dialog) {
				dialog.cancel();
			}
		});
		return builder;
	}
	
	public static Builder makeUnZIPDialog(Context context){
		Builder builder = new Builder(context);
		builder.setMessage(UnZIP_Message);
		builder.setNegativeButton(android.R.string.cancel,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
					}
				});
		builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
			public void onCancel(DialogInterface dialog) {
				dialog.cancel();
			}
		});
		return builder;
	}
}
